/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author gauconpuka
 */
public class ConnectDatabase {

    private Connection ResourceConn = null;

    public Connection getConnection() {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            ResourceConn = DriverManager.getConnection("jdbc:sqlserver://MRHIEP-PC\\SQLEXPRESS:1433;databaseName=ResourceManager", "sa", "1234$");

        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return ResourceConn;
    }

    public boolean testConnection() {
        String sql="SELECT * FROM UserTable";
        Connection conn=getConnection();
        try {
            Statement st = conn.createStatement();
            ResultSet rs=st.executeQuery(sql);
            while(rs.next())
            {
                return true;
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return true;
    }
}
